package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.tools.PageBean;
import com.wechat.back.pojo.Place;
import com.wechat.back.pojo.tools.Result;
import com.wechat.back.service.PlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/place")
@Validated
public class PlaceController {
    @Autowired
    private PlaceService placeService;

    //添加地点
    @OptLog(optModule = "地点模块",optType = "添加", optDesc = "添加地点")
    @PostMapping
    public Result add(@RequestBody @Validated(Place.Add.class) Place place) {
        placeService.add(place);
        return Result.success();
    }
    //列表
    @GetMapping
    public Result<PageBean<Place>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String poiName,
            @RequestParam(required = false) String poiType
            ) {
        PageBean<Place> pl = placeService.list(pageNum, pageSize, poiName, poiType);
        return Result.success(pl);
    }

    //更新
    @OptLog(optModule = "地点模块",optType = "修改", optDesc = "修改地点")
    @PutMapping
    public Result update(@RequestBody @Validated(Place.Update.class) Place place) {
        placeService.update(place);
        return Result.success();
    }

    //删除
    @OptLog(optModule = "地点模块",optType = "删除", optDesc = "删除地点")
    @DeleteMapping
    public Result delete(Integer poiId) {
        placeService.deleteById(poiId);
        return Result.success();
    }

    //根据id查询
    @OptLog(optModule = "地点模块",optType = "查询", optDesc = "查询地点")
    @GetMapping("/findById")
    public Result<Place> findById(Integer poiId) {
        Place place = placeService.findById(poiId);
        return Result.success(place);
    }

    //推荐(评价)
    @OptLog(optModule = "地点模块",optType = "查询", optDesc = "推荐地点")
    @GetMapping("/listByCommentRecommend")
    public Result<List<Place>> listByCommentRecommend(
            @RequestParam(required = false) String poiType
    ) {
        List<Place> pl = placeService.listByCommentRecommend(poiType);
        return Result.success(pl);
    }

    //推荐(内容)
    @OptLog(optModule = "地点模块",optType = "查询", optDesc = "推荐地点")
    @GetMapping("/listByContentRecommend")
    public Result<List<Place>> listByContentRecommend(
            Integer limit,
            String poiType
    ) {
        List<Place> pl = placeService.listByContentRecommend(limit, poiType);
        return Result.success(pl);
    }

    //推荐(热门)
    @OptLog(optModule = "地点模块",optType = "查询", optDesc = "推荐地点")
    @GetMapping("/listByHotRecommend")
    public Result<List<Place>> listByHotRecommend(
            Integer limit,
            @RequestParam(required = false) String poiName,
            @RequestParam(required = false) String poiType
    ) {
        List<Place> pl = placeService.listByHotRecommend(limit,poiName,poiType);
        return Result.success(pl);
    }

    //推荐(用户爱好)
    @GetMapping("/listByUserHobbyRecommend")
    public Result<List<Place>> listByUserHobbyRecommend(
            String poiType
    ) {
        List<Place> pl = placeService.listByUserHobbyRecommend(poiType);
        return Result.success(pl);
    }
}
